package com.xy.tool.report.view;

/**
 * Created by zsp on 2018/12/7.
 */
public class Cell<E> {

    private int span = 1;
    private int rowSpan = 1;
    private TextAlignment horizontalAlignment = TextAlignment.Center;
    private TextAlignment verticalAlignment = TextAlignment.Center;
    private Style style = Style.empty();
    private E value;

    private final static Cell EMPTY = new Cell();

    public Cell() {

    }

    public Cell(E value) {
        this.value = value;
    }

    public Cell<E> withSpan(int value) {
        this.span = value;
        return this;
    }

    public Cell<E> withRowSpan(int value) {
        this.rowSpan = value;
        return this;
    }

    public Cell<E> withHorizontalAlignment(TextAlignment value) {
        this.horizontalAlignment = value;
        return this;
    }

    public Cell<E> withVerticalAlignment(TextAlignment value) {
        this.verticalAlignment = value;
        return this;
    }

    public Cell<E> withStyle(short fontSize, boolean bold) {
        Style style1 = new Style();
        style1.setFontSize(fontSize);
        style1.setBold(bold);
        return withStyle(style1);
    }

    public Cell<E> withStyle(Style style) {
        setStyle(style);
        return this;
    }

    public void setStyle(Style style) {
        if(style == null) {
            this.style = Style.empty();
        } else {
            this.style = style;
        }
    }

    public static Cell empty() {
        return EMPTY;
    }

    public int getSpan() {
        return span;
    }

    public void setSpan(int span) {
        this.span = span;
    }

    public int getRowSpan() {
        return rowSpan;
    }

    public void setRowSpan(int rowSpan) {
        this.rowSpan = rowSpan;
    }

    public TextAlignment getHorizontalAlignment() {
        return horizontalAlignment;
    }

    public void setHorizontalAlignment(TextAlignment horizontalAlignment) {
        this.horizontalAlignment = horizontalAlignment;
    }

    public TextAlignment getVerticalAlignment() {
        return verticalAlignment;
    }

    public void setVerticalAlignment(TextAlignment verticalAlignment) {
        this.verticalAlignment = verticalAlignment;
    }

    public Style getStyle() {
        return style;
    }

    public E getValue() {
        return value;
    }

    public void setValue(E value) {
        this.value = value;
    }

}
